<?php

class YingyangController extends Controller
{
    private $yingyangService = null;
    function __construct($id) {
        parent::__construct($id);
        $this->yingyangService = new YingYangService();
    }
    public function actionIndex()
    {
        
    }
    public function actionHowtoeat()
    {
        $meal["total"] = 1900;
        $meal["meal"] = array();
        $forbid = false;
        $dis = new DiseaseService();
        $result = $dis->getEvaluateList($_GET);
        if (is_int($result)) {
            //JSONHelper::echoJSON(false, $result);
            $result = false;
        }else{
            $dis = array();
            
            foreach ($result["items"] as $key => $it) {
                $value = $it["value"];
                if($value["percent"] > $value["high"]){
                    array_push($dis, $it["name"]);
                }
            }
            $meal = $this->yingyangService->getMealCollocation($_GET);
            if (is_int($meal)){
                //JSONHelper::echoJSON(false, $result);
                $meal = false;
            }
            
            $result = $this->yingyangService->getRecFood($dis);
            if (is_int($result)) {
                //JSONHelper::echoJSON(false, $result);
                $result = false;
            }
            $forbid = $this->yingyangService->getForbidFood($dis,$_GET);
            if (is_int($forbid)) {
                //JSONHelper::echoJSON(false, $result);
                $forbid = false;
            }
        }
        
        $this->renderPartial("howtoeat",array("meal"=>$meal, "result"=>$result,"forbid"=>$forbid));
    }
    public function actionTea()
    {
        if(!isset($_GET["name"])){
            JSONHelper::echoJSON(false, JSONHelper::ERROR_ILLEGAL_REQUEST);
        }
        $this->renderPartial($_GET["name"]);        
    }
}

